package com.wzgl.core.webmagic.processor;

import java.io.Serializable;

import org.quartz.JobExecutionException;

import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;

public class HttpPageForImgProcess implements PageProcessor,Serializable {
	static String  cont = "";
    static String repex = "";
	private static final long serialVersionUID = 1L;
    private static Spider s ;
    private Site site = Site.me().setRetryTimes(1).setSleepTime(1000).addHeader("Accept-Encoding", "/");
	
    public static String getRepex() {
		return repex;
	}
	public static void setRepex(String repex) {
		HttpPageProcessor.repex = repex;
	}
	@Override
    public Site getSite() {
        return site;
    }
	public static String execute(String herf,String r) throws JobExecutionException {
		// TODO Auto-generated method stub
		s = Spider.create(new HttpPageForImgProcess()).addUrl(herf).thread(1);  
		setRepex(r);
    	s.run();
    	return cont;
	}
	
	@Override
    public void process(Page page) {
		String pic_text = page.getHtml().xpath("//div[@id='picBody']/p").toString();	
		//正文
    	cont = pic_text.substring(0, pic_text.lastIndexOf("</p>")+4);
	}
}
